<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"  %>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@ page import="java.io.PrintWriter" %>
<%
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
	JSONObject retObject = new JSONObject();
	retObject.put("code", 200);
	retObject.put("msg", "操作成功");
	try{
    	// URL 参数
	    Object name  = request.getParameter("name");              // 子奖项名称
	    Object awardsId  = request.getParameter("awardsId");     // 父奖项ID
	    Object flagData  = request.getParameter("flagData");     // 父奖项ID
	    Object subAwardsId  = request.getParameter("subAwardsId");     // 父奖项ID
	    String sql = "select count(1) as count from vote_awards_subname where name = N'"+name+"' AND awards_id = " +awardsId +" and is_del = 0";
	    RecordSet set = new RecordSet();
	    set.executeSql(sql);
	       set.next(); 
	   	if(set.getInt("count")>0){
	   		throw new RuntimeException("数据重复了!");
	   	}
 
	      sql = "INSERT INTO vote_awards_subname(" +
	            (name==null?"":"name, ") +
	            (awardsId==null?"":"awards_id, ") +
	            "create_time) " +
	            "values(" +
	            (name==null?"":"N'"+name+"', ") +
	            (awardsId==null?"":awardsId+", ") +
	            "GETDATE())";
	      RecordSet set1 = new RecordSet();
	      set1.executeSql(sql);
    } catch (Exception e) {
        e.printStackTrace();
        retObject.put("code", -1);
        retObject.put("msg", e.getMessage());
    } finally {
		PrintWriter printWriter = response.getWriter();
		printWriter.append(retObject.toJSONString());
    }
%>
 